package org.example.minebackend.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.minebackend.pojo.DetailOfRecipe;
import org.example.minebackend.pojo.Herb;
import org.example.minebackend.pojo.RecipeEntry;
import org.example.minebackend.pojo.Result;
import org.example.minebackend.service.HealthClubService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin("*")
@RestController
@Slf4j
@RequestMapping("/healthclub")
public class HealthClubController {
    @Autowired
    HealthClubService healthClubService;
    @GetMapping("/recipes/display")
    public Result getRecipeEntry(@RequestParam String body) {
        log.info("体质类型为{}", body);
        List<RecipeEntry> result = healthClubService.getRecipeEntry(body);
        return Result.success(result);
    }

    @GetMapping("/recipes/details/{id}")
    public Result getRecipeDetails(@PathVariable Integer id) {
        log.info("请求菜谱的详细制作：{}", id);
        DetailOfRecipe result = healthClubService.getRecipeDetails(id);
        return Result.success(result);
    }

    @GetMapping("/recipes/collection")
    public Result addRecipeCollection(@RequestParam Integer userId, @RequestParam Integer recipeId) {
        log.info("插入参数(userId, recipeId)分别为：{}, {}", userId, recipeId);
        int n = healthClubService.addRecipeCollection(userId, recipeId);
        if(n == 0) return Result.success("success");
        return Result.error("fail");
    }

    @GetMapping("/recipes/judgecollection")
    public Result judgeCollection(@RequestParam Integer userId, @RequestParam Integer recipeId) {
        log.info("judegeCollection插入参数(userId, recipeId)分别为：{}, {}", userId, recipeId);
        int len = healthClubService.judgeCollection(userId, recipeId);
        if(len == 1) {
            return Result.success("success");
        }
        return Result.error("fail");
    }

    @DeleteMapping("/recipes/deletecollection")
    public Result deleteCollection(@RequestParam Integer userId, @RequestParam Integer recipeId) {
        log.info("deleteCollection删除参数(userId, recipeId)分别为：{}, {}", userId, recipeId);
        int n = healthClubService.deleteCollection(userId, recipeId);
        if(n == 1) return Result.success("success");
        return Result.error("fail");
    }

    @GetMapping("/herbs")
    public Result getHerbsByBody(@RequestParam String body) {
        log.info("请求中草药类型：{}", body);
        List<Herb> result = healthClubService.getHerbsByBody(body);
        return Result.success(result);
    }

}
